import { MenuObject } from "types";
import { create } from "zustand";
import { persist } from "zustand/middleware";

interface MenuStore {
    menu: MenuObject[],
    setMenu: (menu: any[]) => void,
    getMenu: () => MenuObject[]
}

const store = persist<MenuStore>((set, get) => ({
    menu: [],
    setMenu: (menuList: MenuObject[]) => {
        set((state) => {
            state.menu = menuList;
            return {
               ...state
            }
        })
    },
    getMenu: () => get().menu
}), { name: 'menu' })

const menuStore = create(store);

export default menuStore